/*
 * message_app_input_changed.cpp
 *
 *  Created on: 28 Oca 2012
 *      Author: root
 */

#include "message_activity_input_changed.h"
#include "../../application.h"

namespace androidplus {
namespace messaging{
namespace activity{

message_activity_input_changed::message_activity_input_changed(AInputQueue *_queue):message(MSG_ACTIVITY_INPUT_CHANGED),queue(_queue) {


}

message_activity_input_changed::~message_activity_input_changed() {

}

void message_activity_input_changed::execute()
{
	LOGI("Input Queue Changed");

	application::cur_app()->cur_activity()->threading_lock_mutex();

	            if (application::cur_app()->cur_activity()->input.queue != NULL) {
	                AInputQueue_detachLooper(application::cur_app()->cur_activity()->input.queue);
	            }

	            application::cur_app()->cur_activity()->input.queue  = queue;
	            if (application::cur_app()->cur_activity()->input.queue  != NULL) {
	                LOGI("Attaching Input Queue To Looper");
	                AInputQueue_attachLooper(application::cur_app()->cur_activity()->input.queue ,application::cur_app()->cur_activity()->poll.looper, LOOPER_ID_INPUT, NULL,NULL);
	            }
	            application::cur_app()->cur_activity()->threading_condition_broadcast();
	            application::cur_app()->cur_activity()->threading_unlock_mutex();

}

}
}
} /* namespace androidplus */
